//
//  SISSPropertyCenterCheckMortgageShowViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/10/26.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSPropertyCenterCheckMortgageShowViewController.h"
#import "SISSTitleView.h"
#import "SISSShowView.h"
#import "SISSPassengerProgressViewController.h"
#import "SISSPropertyCenterCheckMortgageViewController.h"
#import "SISSNetworkingManager+PassengerProgress.h"

@interface SISSPropertyCenterCheckMortgageShowViewController ()

/// 预约信息
@property (weak, nonatomic) SISSTitleView *reserveTitleView;
@property (weak, nonatomic) SISSShowView *servicePointShowView;
@property (weak, nonatomic) SISSShowView *timeShowView;
@property (weak, nonatomic) SISSShowView *addressShowView;

/// 注意事项
@property (weak, nonatomic) SISSTitleView *noticeTitleView;
@property (weak, nonatomic) UILabel *noticeLabel;

///
@property (weak, nonatomic) UIButton *editButton;
@property (strong, nonatomic) SISSPropertyMortgageInfoModel *propertyMortgageInfoModel;

@end

@implementation SISSPropertyCenterCheckMortgageShowViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"过户预约信息记录";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(backItemAction)];
    [self requestData];
}

/**
 返回按钮点击事件
 */
- (void)backItemAction {
    
    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:[SISSPassengerProgressViewController class]]) {
            [self.navigationController popToViewController:controller animated:YES];
        }
    }
}

- (void)requestData {

    [kNetworkManager requestPropertyMortgageInfoWithAdbpId:self.adbpId success:^(SISSPropertyMortgageInfoModel *propertyMortgageInfoModel) {
        self.propertyMortgageInfoModel = propertyMortgageInfoModel;
        if (self.isHistory && !propertyMortgageInfoModel) {
            for (UIView *view in self.view.subviews) {
                view.hidden = YES;
            }
        }
    } failed:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

- (void)setPropertyMortgageInfoModel:(SISSPropertyMortgageInfoModel *)propertyMortgageInfoModel {
    _propertyMortgageInfoModel = propertyMortgageInfoModel;
    self.servicePointShowView.rightStr = propertyMortgageInfoModel.branch;
    self.timeShowView.rightStr = propertyMortgageInfoModel.applyTime;
    self.addressShowView.rightStr = propertyMortgageInfoModel.address;
    
    self.noticeLabel.text = propertyMortgageInfoModel.attention;
}


// 编辑按钮点击事件
- (void)editButtonClickAction {
    SISSPropertyCenterCheckMortgageViewController *vc = [[SISSPropertyCenterCheckMortgageViewController alloc] init];
    vc.adbpId = self.adbpId;
    vc.propertyMortgageInfoModel = self.propertyMortgageInfoModel;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)setupSubviews {
    [super setupSubviews];
    
    SISSTitleView *reserveTitleView = [[SISSTitleView alloc] init];
    reserveTitleView.titleStr = @"预约信息";
    [self.containerView addSubview:reserveTitleView];
    self.reserveTitleView = reserveTitleView;
    
    SISSShowView *servicePointShowView = [[SISSShowView alloc] init];
    servicePointShowView.leftStr = @"抵押办理网点：";
    servicePointShowView.isShowBottomLine = YES;
    [self.containerView addSubview:servicePointShowView];
    self.servicePointShowView = servicePointShowView;
    
    SISSShowView *timeShowView = [[SISSShowView alloc] init];
    timeShowView.leftStr = @"时间：";
    timeShowView.isShowBottomLine = YES;
    [self.containerView addSubview:timeShowView];
    self.timeShowView = timeShowView;
    
    SISSShowView *addressShowView = [[SISSShowView alloc] init];
    addressShowView.leftStr = @"地址：";
    addressShowView.isShowBottomLine = YES;
    [self.containerView addSubview:addressShowView];
    self.addressShowView = addressShowView;
    
    
    SISSTitleView *noticeTitleView = [[SISSTitleView alloc] init];
    noticeTitleView.titleStr = @"注意事项";
    [self.containerView addSubview:noticeTitleView];
    self.noticeTitleView = noticeTitleView;
    
    UILabel *noticeLabel = [UILabel yyr_labelWithText:@"" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self.containerView addSubview:noticeLabel];
    self.noticeLabel = noticeLabel;
    
    UIButton *editButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [editButton setTitle:@"录入进度" forState:UIControlStateNormal];
    [editButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [editButton setBackgroundColor:MAIN_COLOR];
    [editButton addTarget:self action:@selector(editButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:editButton];
    self.editButton = editButton;
}

- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf;
    [self.reserveTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.containerView);
        make.left.right.equalTo(weakSelf.containerView);
        make.height.mas_equalTo(5 * globelMargin);
    }];
    
    [self.servicePointShowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.reserveTitleView.mas_bottom);
        make.left.right.equalTo(weakSelf.containerView);
    }];
    
    [self.timeShowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.servicePointShowView.mas_bottom);
        make.left.right.equalTo(weakSelf.containerView);
    }];
    
    [self.addressShowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.timeShowView.mas_bottom);
        make.left.right.equalTo(weakSelf.containerView);
    }];
    
    [self.noticeTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.addressShowView.mas_bottom).offset(2 * globelMargin);
        make.left.right.equalTo(weakSelf.containerView);
        make.height.mas_equalTo(5 * globelMargin);
    }];
    
    [self.noticeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.noticeTitleView.mas_bottom).offset(2 * globelMargin);
        make.left.equalTo(weakSelf.containerView).offset(2 * globelMargin);
        make.right.equalTo(weakSelf.containerView).offset(-2 * globelMargin);
        make.height.mas_equalTo(8 * globelMargin);
        make.bottom.equalTo(weakSelf.containerView).offset(-5 * globelMargin);
    }];
    
    [self.editButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(weakSelf.mas_bottomLayoutGuideTop);
        make.centerX.equalTo(weakSelf.view);
        make.width.mas_equalTo(0.8 * SCREEN_WIDTH);
        make.height.mas_equalTo(5 * globelMargin);
    }];
    
}

@end
